import pygame
from pygame import *

from pygui import *
from ezpygui import *
from pyconsole import *

pygame.init()

class Game:
    #called when the game is initialized
    def __init__(self):
        #make the screen buffer
        self.screen = pygame.display.set_mode((800,600))
        
        #make a background buffer
        self.bg = pygame.Surface((800, 600)).convert()
        self.bg.fill((175, 175, 200))
        
        #create a default font
        self.font = pygame.font.Font(None, 16)
        
        #this is the code I wrote before: handles the GUI and in-game console
        wmgr.setup(self.screen)
        command.setup(self.screen)
        
    #display the main menu
    def MainMenu(self):
        button = wimgbutton("play", "playbtn.png") #make a play button
        wmgr.add(button)    #add it to the GUI
        button.align(ALIGN_CENTER)    #note: Must be aligned AFTER adding, or else it doesnt know what to align to.
        
        while True: #loop until we break out manually.
            #get events.
            for event in pygame.event.get():
                #pass events to GUI
                wmgr.injectEvent(event)
                
                if event.type == QUIT:
                    sys.exit()
                if event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        sys.exit()
                    elif event.key == K_BACKQUOTE:
                        ret = command.showConsole(globals(), locals())
                        if ret is 0:
                            sys.exit()
                            
            #blit the background to the screen, blanking it
            self.screen.blit(self.bg, (0, 0))
            wmgr.draw()
            
            
            pygame.display.flip()
            
#create an instance of the game
game = Game()

#start the main menu
game.MainMenu()

